package com.buddy.design.pattern._06template.jdbc;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.List;

public class MemmberDao extends JdbcTemplate {

    public MemmberDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<?> selectAll() {
        String sql = "select * from t_member";
        return super.executeQuery(sql, new RowMapper<Member>() {
            @Override
            public Member mapRow(ResultSet resultSet, int rowNum) throws Exception {
                Member member = new Member();
                //字段过多，原型模式解决
                member.setUserName(resultSet.getString("username"));
                member.setPassword(resultSet.getString("password"));
                member.setAge(resultSet.getInt("age"));
                member.setAddr(resultSet.getString("addr"));
                return member;
            }
        }, null);
    }
}
